package 刷题10月.leecodehot100;
// https://leetcode-cn.com/problems/counting-bits/
public class 位运算338比特位计数1017 {

        public int[] countBits(int n) {
            int arr[]=new int[n+1];
            for(int i=0;i<n+1;i++){
                arr[i]=count(i);
            }
            return arr;
        }
        public static int count(int n){
            int count=0;//统计1的个数
            int yushu=0;//余数
            while(n!=0){
                yushu=n%2;
                if(yushu==1){
                    count++;
                }
                n=n/2;
            }
            return count;
        }

}
